<template>
    <div class="container">

        <Row class="btn-action">
            <Col span="24">
                <Button type="primary" class="mp10" @click="chuanSongAction">档案转送</Button>
                <Button type="primary" @click="importExcel">数据导入</Button>
            </Col>
        </Row>

        <div class="opt-area-02">
            <div class="left-con">
                录入总数: <span>{{countData.gjnum}} 条</span> |
                提交记录: <span>{{countData.tjnum}} 条</span> |
                暂存: <span>{{countData.zcnum}} 条</span>
            </div>
            <div class="right-con">
                <div class="input-frame">
                    <Select v-model="params.state" style="width:200px" @on-change="selectlist">
                        <Option value="">全部</Option>
                        <Option value="1">暂存</Option>
                        <Option value="2">已提交</Option>
                        <Option value="3">交接完毕</Option>
                    </Select>
                </div>
                <div class="input-frame">
                    <Input type="text" @on-click="selectlist(1)" placeholder="请输入档案号" v-model="params.recode_no"
                           icon="ios-search"/>
                </div>
                <div class="input-frame">
                    <Input type="text" @on-click="selectlist(1)" placeholder="请输入姓名" v-model="params.name"
                           icon="ios-search"/>
                </div>
                <div class="input-frame">
                    <Input type="text" @on-click="selectlist(1)" placeholder="请输入身份证号" v-model="params.id_card"
                           icon="ios-search"/>
                </div>
            </div>
        </div>

        <Table :loading="countData.loading" border :columns="columns2" :data="fcDataList" size="small" @on-selection-change="selectList">
            <template slot-scope="{ row }" slot="sex">
                <div v-if="row.sex==='1'">男</div>
                <div v-if="row.sex==='0'">女</div>
            </template>
            <template slot="action" slot-scope="{ row }">
                <Button class="table-action-btn" type="info" size="small" @click="showdetail(row, 'info')">详情</Button>
                <Button v-if="row.state==='1'||row.state==='2'" class="table-action-btn" type="success" size="small"
                        @click="showdetail(row, 'edit')">编辑
                </Button>
                <!--                <Button class="table-action-btn" type="success" size="small"-->
                <!--                        @click="uploadImgAll(row, 'uploadImg')">批量上传-->
                <!--                </Button>-->
                <Button type="error" size="small" @click="deleteRow(row)">删除</Button>
            </template>
        </Table>
        <Row type="flex" justify="end" class="page_style">
            <Page :current="params.pageNo" :total="params.totalRecord" show-sizer :page-size="params.pageSize"
                  show-total @on-change="pageAction" @on-page-size-change="pageSizeChange"/>
        </Row>
        <img-import-service ref="imgService" :options="row"></img-import-service>
        <turn-people-model ref="turnPeopleModel" :options="selection" @clean="clean"></turn-people-model>
    </div>
</template>

<script>
import ImgImportService from '@/components/img-import-service/index'
import TurnPeopleModel from './components/turn-people-model/index'
import { recordList, getRecordNum } from '@/api/record'

export default {
  name: 'houseList',
  components: { TurnPeopleModel, ImgImportService },
  data () {
    return {
      row: {},
      countData: { loading: true, gjnum: 0, tjnum: 0, zcnum: 0 },
      params: { name: '', type: '', pageNo: 1, pageSize: 10, totalRecord: 0, state: '' },
      columns2: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        { title: '档案号', key: 'recode_no', width: 150, align: 'center' },
        { title: '姓名', key: 'name', width: 170, align: 'center' },
        { title: '身份证号', key: 'idcard', width: 160, align: 'center' },
        { title: '性别', slot: 'sex', width: 140, align: 'center' },
        { title: '机构编号', key: 'company_code', width: 150, align: 'left' },
        { title: '档案交接号', key: 'manager_recode_no', width: 150, align: 'left' },
        { title: '交接单位', key: 'accept_company_code', width: 150, align: 'left' },
        { title: '操作', align: 'center', minWidth: 250, slot: 'action', fixed: 'right' }
      ],
      fcDataList: [],
      selection: []
    }
  },
  methods: {
    getRecordNum () {
      getRecordNum().then(ret => {
        if (ret.data.errcode === 0) {
          this.countData.gjnum = ret.data.data.gjNum
          this.countData.tjnum = ret.data.data.tjNum
          this.countData.zcnum = ret.data.data.zcNum
        }
      })
    },
    clean () {
      this.selection = []
      this.getList()
    },
    selectList (selection) {
      this.selection = selection
    },
    pageAction (page) {
      this.params.pageNo = page
      this.getList()
    },
    selectlist () {
      this.params.pageNo = 1
      this.params.type = this.type
      this.getList()
    },
    getList () {
      recordList(this.params).then(res => {
        let result = res.data.data
        if (res.data.errcode === 0 || res.data.errcode === 1001) {
          this.getRecordNum()
          this.fcDataList = res.data.data.results
          this.fcDataList.forEach(item => {
            if (item.state !== '1') {
              item['_disabled'] = true
            }
          })
          this.params.pageNo = result.pageNo
          this.params.pageSize = result.pageSize
          this.params.totalPage = result.totalPage
          this.params.totalRecord = result.totalRecord
          this.countData.loading = false
        }
      })
    },
    deleteRow (row) {
      this.$Modal.confirm({
        title: '确认删除此档案信息吗？',
        content: '删除后不可恢复，请确认后再操作！',
        onOk: () => {

        }
      })
    },
    showdetail (row, what) {
      this.$router.push({ path: '/record/add', query: { id: row.id, what: what } })
    },
    uploadImgAll (row, what) {
      this.row = row
      this.$refs.imgService.modelAction()
    },
    pageSizeChange (e) {
      this.params.pageSize = e
      this.selectlist(this.params.pageNo)
    },
    chuanSongAction () {
      if (this.selection.length === 0) {
        this.$Message.info('请选择档案！')
      } else {
        this.$refs.turnPeopleModel.modelAction()
      }
    },
    importExcel () {
      this.$router.push({
        name: 'recordExcel'
      })
    }
  },
  mounted () {
    this.selectlist()
  }
}
</script>

<style scoped>
    .page_style {
        margin: 20px 5px;
    }

    .input-frame {
        width: 120px;
        margin-right: 10px;
    }

    .house-list > .group {
        background: white;
        padding: 10px;
        margin-top: 10px;
    }

    .house-list > .group > .item {
        border-bottom: 1px solid #f5f5f5;
        padding: 10px 0;
    }

    .house-list > .group > .item .top {
        display: flex;
        justify-content: space-between;
        margin-bottom: 5px;
    }

    .house-list > .group > .item .title {
        font-size: 14px;
        color: #333333;
    }

    .house-list > .group > .item .address {
        font-size: 12px;
        color: gray;
        display: flex;
        align-items: center;
    }

    .house-list > .group > .item .detail {
        font-size: 12px;
        color: dodgerblue;
    }

    .opt-area-02 {
        display: flex;
        align-items: center;
        flex-direction: column;
        border: 1px solid #abdcff;
        background-color: #f0faff;
        padding: 8px 16px 8px 16px;
        border-radius: 4px;
        margin-bottom: 10px;
    }

    .opt-area-02 .right-con {
        width: 100%;
        margin-top: 5px;
        display: flex;
    }

    .opt-area-02 .left-con {
        font-size: 14px;
        width: 100%;
    }

    .opt-area-02 .left-con span {
        font-weight: bold;
    }

    .opt-area-02 .right-con input {
        width: 150px;
        margin-right: 10px;
    }

    .opt-area-02 .right-con .input-frame {
        width: 200px;
        margin-right: 10px;
    }

    .table-action-btn {
        margin-right: 3px;
    }

    .container >>> .ivu-btn-small {
        height: 24px;
        padding: 0 5px;
        font-size: 12px;
        border-radius: 3px;
    }

    .btn-action {
        margin-bottom: 10px;
    }

    .mp10 {
        margin-right: 10px;
    }
</style>
